Skip to content

Update logs#299

Open
7eliassen wants to merge 10 commits intomainfrom
chore/logs-and-optimization
Open

Update logs#299
7eliassen wants to merge 10 commits intomainfrom
chore/logs-and-optimization

Conversation

@7eliassen
Copy link

Changes:

  • Added execution time tracking (durationMs) for database queries.
  • Implemented request ID (reqId) propagation to middlewares, policies, and database queries.
  • Added logging for policy executions and included middleware/policy modules in the logging configuration

Details:

  • Created reqId.context.ts for async context management
  • Added reqIdContext middleware to inject request IDs
  • Modified Sequelize configuration to include durationMs and reqId in query logs
  • Updated eslint config

@github-actions
Copy link

github-actions bot commented Mar 11, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 85.97% (🎯 80%)
⬆️ +0.06%
9027 / 10500
🔵 Statements 85.97% (🎯 80%)
⬆️ +0.06%
9027 / 10500
🔵 Functions 79.77% (🎯 80%)
⬆️ +0.24%
280 / 351
🔵 Branches 85.02% (🎯 80%)
⬆️ +0.45%
460 / 541
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/infrastructure/config/index.ts 98.99%
⬆️ +0.02%
50%
🟰 ±0%
100%
🟰 ±0%
98.99%
⬆️ +0.02%
189-190
src/infrastructure/logging/index.ts 95.71%
⬆️ +3.03%
80%
⬆️ +46.67%
100%
🟰 ±0%
95.71%
⬆️ +3.03%
8, 40-41
src/infrastructure/logging/reqId.context.ts 100% 100% 100% 100%
src/presentation/http/http-api.ts 96.08%
⬆️ +0.02%
90.32%
🟰 ±0%
93.75%
🟰 ±0%
96.08%
⬆️ +0.02%
103-111, 122-123, 325-326, 350-351
src/presentation/http/middlewares/common/reqIdContext.ts 100% 100% 100% 100%
src/presentation/http/middlewares/common/userIdResolver.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/presentation/http/middlewares/note/useNoteResolver.ts 97.22%
⬇️ -0.14%
85.71%
🟰 ±0%
100%
🟰 ±0%
97.22%
⬇️ -0.14%
59-60
src/presentation/http/middlewares/noteSettings/useMemberRoleResolver.ts 78.84%
⬇️ -7.69%
71.42%
🟰 ±0%
100%
🟰 ±0%
78.84%
⬇️ -7.69%
27-28, 41-49
src/presentation/http/middlewares/noteSettings/useNoteSettingsResolver.ts 94.87%
⬇️ -0.47%
80%
🟰 ±0%
100%
🟰 ±0%
94.87%
⬇️ -0.47%
25-26
src/presentation/http/policies/authRequired.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/presentation/http/policies/notePublicOrUserInTeam.ts 94.44%
⬇️ -3.33%
88.88%
⬆️ +1.38%
100%
🟰 ±0%
94.44%
⬇️ -3.33%
20-22
src/presentation/http/policies/userCanEdit.ts 93.61%
⬇️ -3.68%
85.71%
⬆️ +2.38%
100%
🟰 ±0%
93.61%
⬇️ -3.68%
29-31
src/repository/storage/postgres/orm/sequelize/index.ts 97.05%
⬆️ +0.39%
83.33%
⬆️ +3.33%
100%
🟰 ±0%
97.05%
⬆️ +0.39%
58-59
Generated in workflow #910 for commit 8596447 by the Vitest Coverage Report Action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds request-scoped logging to improve observability by propagating a request ID (reqId) through HTTP handling and including both reqId and query duration (durationMs) in database logs.

Changes:

  • Introduce AsyncLocalStorage-based reqId context and register it as an onRequest hook.
  • Add getRequestLogger() and migrate middlewares/policies to use request-scoped logging.
  • Enable Sequelize query benchmarking and emit query logs with durationMs; extend logging config with middlewares/policies modules.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/repository/storage/postgres/orm/sequelize/index.ts Enables benchmarked Sequelize logging and logs durationMs via request-scoped logger.
src/presentation/http/policies/userCanEdit.ts Adds request-scoped logging around policy decisions.
src/presentation/http/policies/notePublicOrUserInTeam.ts Adds request-scoped logging for note access policy flow.
src/presentation/http/policies/authRequired.ts Adds request-scoped logging for authentication requirement policy.
src/presentation/http/middlewares/noteSettings/useNoteSettingsResolver.ts Switches middleware logging to request-scoped logger.
src/presentation/http/middlewares/noteSettings/useMemberRoleResolver.ts Switches to request-scoped logger and improves error message formatting.
src/presentation/http/middlewares/note/useNoteResolver.ts Switches middleware logging to request-scoped logger.
src/presentation/http/middlewares/common/userIdResolver.ts Removes injected logger parameter and uses request-scoped logger inside hook.
src/presentation/http/middlewares/common/reqIdContext.ts New middleware to establish reqId async context per request.
src/presentation/http/http-api.ts Registers reqId context middleware and updates userId resolver wiring.
src/infrastructure/logging/reqId.context.ts New AsyncLocalStorage store + helper to fetch current reqId.
src/infrastructure/logging/index.ts Adds getRequestLogger() which enriches logs with reqId when present.
src/infrastructure/config/index.ts Extends LoggingConfig schema/defaults to include middlewares and policies.
eslint.config.mjs Tightens Node built-in feature linting via n/no-unsupported-features/node-builtins.
app-config.yaml Adds log levels for new middlewares and policies logger modules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants